<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once('base_mapper.php');
Class Contact_mapper extends Base_mapper{
	protected $object_class = 'contact_object';
	
	protected $table = 'contacts';
	
	protected $primary_key = 'id';
	
	protected function doBuildObject($row){
		return new Contact_object($row->id, $row->title, $row->designation, $row->firstname, $row->lastname, $row->email, $row->phone);
	}
	public function getContactByVendorAndType($vendor_id, $contact_type){
		$result = array();
		$query = $this->db->get_where('vendor_has_contact', array('vendor_id'=>$vendor_id, 'type'=>$contact_type));
		foreach($query->result() as $row){
			$result[] = $this->Find($row->contact_id);
		}
		return $result;
	}
	protected function doInsert($obj){
		throw new Exception("overwrite the insert" . get_class($this));
	}
	protected function doUpdate($obj){
		throw new Exception("overwrite the update" . get_class($this));
	}
	protected function doDelete($obj){
		$tables = array('vendors_has_contacts');
		$this->db->where('contacts_id', $obj->getId());
		$this->db->delete($tables);
		parent::doDelete($obj);
	}
}